package rabbitmq.pushOrPull;

import com.rabbitmq.client.*;
import rabbitmq.Connect;
import rabbitmq.constant.Constants;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConsumerPull {
    public static void main(String[] args) throws IOException, TimeoutException {
        // 1. 创建对应的工厂
        // 2. 创建connection
        Connection connection = Connect.createConnection();
        // 3. 创建 channel
        Channel channel = connection.createChannel();
        // 4. 设置queue 和 exchange
        channel.queueDeclare(Constants.PULL_QUEUE, true, false, true, null);
        // 5. 消费

        GetResponse getResponse = channel.basicGet(Constants.PULL_QUEUE, true);

        System.out.println("收到消息： " + new String(getResponse.getBody()));
//        channel.close();
//        connection.close();

    }
}
